package com.tulingxueyuan.mall.modules.pms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tulingxueyuan.mall.modules.pms.model.PmsBrand;
import com.tulingxueyuan.mall.modules.pms.mapper.PmsBrandMapper;
import com.tulingxueyuan.mall.modules.pms.service.PmsBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 品牌表 服务实现类
 * </p>
 *
 * @author XuShu
 * @since 2023-05-08
 */
@Service
public class PmsBrandServiceImpl extends ServiceImpl<PmsBrandMapper, PmsBrand> implements PmsBrandService {

    @Override
    public Page listPage(String keyword,Integer pageNum, Integer pageSize) {
        Page<PmsBrand> pageInfo = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<PmsBrand> wrapper = new LambdaQueryWrapper<>();
        if (keyword != null && keyword != ""){
            wrapper.like(PmsBrand::getName,keyword);
        }
        wrapper.orderByAsc(PmsBrand::getSort);
        this.page(pageInfo,wrapper);
        return pageInfo;
    }

    /**
     * 修改状态
     * @param ids
     * @param factory_status
     * @param factoryStatus
     * @return
     */
    @Override
    public boolean updateStatus(List<Long> ids, String factory_status, Long factoryStatus) {
        UpdateWrapper<PmsBrand> wrapper = new UpdateWrapper<>();
        wrapper.set(factory_status,factoryStatus)
                .in("id",ids);

        return this.update(wrapper );
    }
}
